
import java.awt.event.MouseEvent;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Okno.java
 *
 * Created on Oct 16, 2011, 9:32:04 PM
 */
/**
 *
 * @author Riso-Desktop
 */
public class Okno extends JApplet implements Runnable{

    /** Creates new form Okno */
    Hra hra;
    Highscore h = new Highscore();
    static boolean hrabezi=false;
    Thread kontrola;
    JLabel exit = new JLabel("quit game");
    JLabel pozadie = new JLabel(new javax.swing.ImageIcon(getClass().getResource("/img/hra_back.png")));
    public void init(){
        setSize(960, 600);
    }
    public Okno() {
    }
    public void novahra(){
        if(hrabezi==false){
        exit.addMouseListener(new java.awt.event.MouseAdapter() {
                @Override
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                kliknute(evt);
            }
                @Override
            public void mouseEntered(java.awt.event.MouseEvent evt){
                over(evt);
            }
        });
        exit.setBounds(590, 565, 60, 20);
        add(exit);
        hra = new Hra();
        this.setBounds(0, 0, 960, 600);
        pozadie.setBounds(0, 0, 960, 600);
        setFocusable(true);
        hra.setBounds(0, 0, 960, 600);
        hra.novahra();
        kontrola = new Thread(this);
        kontrola.start();
        this.add(hra);
        this.add(pozadie);
        hrabezi= true;
        }
    }

    private void over(MouseEvent evt){
        setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
    }
    private void kliknute(MouseEvent evt){
        this.setVisible(false);
        hra.hrabezi=false;
        hra.setVisible(false);
        kontrola=null;
        hrabezi= false;
        hra.zvukstop();
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 960, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 600, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables


    @Override
    public void run() {
        while(kontrola!=null){
            try {
                kontrola.sleep(50);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if(hra.cas<=0){
                Highscore.sz.pridaj((String)JOptionPane.showInputDialog("Zadaj svoje meno:"), Hra.skore);
                h.ulozskore();
                this.setVisible(false);
                hra.hrabezi=false;
                hra.setVisible(false);
                kontrola=null;
                hrabezi= false;
            }
        }
        
        
    }



}
